package com.whlilong.jxc.filemanager.editor;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;

import com.whlilong.jxc.db.DbManager;
import com.whlilong.jxc.dialog.BusinessInfoSearchByConditon;
import com.whlilong.jxc.editor.support.BussinessInfoEditorSupport;
import com.whlilong.jxc.listener.IEditorListener;
import com.whlilong.jxc.model.Hsinfo;
import com.whlilong.jxc.print.IconSource;
import com.whlilong.jxc.print.PDocument;
import com.whlilong.jxc.print.PHLine;
import com.whlilong.jxc.print.PTableBoxProvider;
import com.whlilong.jxc.print.PTextBox;
import com.whlilong.jxc.print.PVSpace;
import com.whlilong.jxc.print.PrintPreview;
import com.whlilong.jxc.print.SWTPTable;
import com.whlilong.jxc.service.editor.IEditorService;
import com.whlilong.jxc.sys.CnToSpellFirstChar;
import com.whlilong.jxc.sys.ExtentionInfo;
import com.whlilong.jxc.sys.SetTableColColorListener;
import com.whlilong.jxc.treemodel.KeshangTreeChildren;
import com.whlilong.jxc.treemodel.KeshangTreeParent;
import com.whlilong.jxc.treemodel.MerchantTypeTreeChildren;
import com.whlilong.jxc.treemodel.MerchantTypeTreeParent;
import com.whlilong.jxc.ui.provider.BusinessInfoContentProvider;
import com.whlilong.jxc.ui.provider.BusinessInfoLableProvider;
import com.whlilong.jxc.ui.provider.DistrictTreeContentProvider;
import com.whlilong.jxc.ui.provider.DistrictTreeLabelProvider;
import com.whlilong.jxc.ui.provider.MerchantTypeTreeContentProvider;
import com.whlilong.jxc.ui.provider.MerchantTypeTreeLabelProvider;
import com.whlilong.jxc.ui.sorter.BusinessInfoSorter;

/**
 * 货商信息编辑器
 * 
 * @author sjy
 * 
 */
public class BusinessInfoEditor extends AbstractEditor implements
		IEditorService, IEditorListener {

	private Label infoLabel;
	private Label hsbhLabel;
	private Text hsbh;
	private Label hsnameLabel;
	private Text hsname;
	private Button findBt;
	protected String hsid;
	protected String hsName;
	private Table table;
	private List<Hsinfo> list = new ArrayList<Hsinfo>();
	protected int selItem;
	protected Text text;
	private Combo combo;
	private int i = 0;
	protected Combo tableCombo;
	private TableLayout tableLayout;
	protected ExtentionInfo extentionInfo = null;
	private boolean isSave = true;
	private Shell shell;

	public BusinessInfoEditor() {
		// TODO Auto-generated constructor stub
	}

	protected Control createGroupText(Composite parent) {
		// TODO Auto-generated method stub
		Composite container = new Composite(parent, SWT.NONE);
		final GridLayout gl = new GridLayout(2, false);
		container.setLayout(gl);
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
		combo = new Combo(container, SWT.READ_ONLY);
		combo.add("1--区域");
		combo.add("2--类别");
		combo.select(0);
		combo.setLayoutData(gd);
		createTableViewer(container);
		addComboListener(container);
		createTreeViewer(container);

		return container;
	}

	private void addComboListener(final Composite container) {
		// TODO Auto-generated method stub
		combo.addSelectionListener(new SelectionListener() {

			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				// TODO Auto-generated method stub

			}

			@SuppressWarnings("static-access")
			@Override
			public void widgetSelected(SelectionEvent e) {
				// TODO Auto-generated method stub
				i = combo.getSelectionIndex();
				if (i == 0) {
					treeViewer.getTree().getColumn(0).setText("货商地区");
					treeViewer
							.setContentProvider(new DistrictTreeContentProvider());
					treeViewer
							.setLabelProvider(new DistrictTreeLabelProvider());
					treeViewer.setInput(extentionInfo.getInstance()
							.getKeshang());

					treeViewer.expandToLevel(2);
				}
				if (i == 1) {
					treeViewer.getTree().getColumn(0).setText("货商类别");
					treeViewer
							.setContentProvider(new MerchantTypeTreeContentProvider());
					treeViewer
							.setLabelProvider(new MerchantTypeTreeLabelProvider());
					treeViewer
							.setInput(extentionInfo.getInstance().getKstype());

					treeViewer.expandToLevel(2);
				}
			}

		});
	}

	private void createTableViewer(Composite parent) {
		// TODO Auto-generated method stub
		GridData gd = new GridData(GridData.FILL_BOTH);
		gd.verticalSpan = 2;
		Composite composite = new Composite(parent, SWT.NONE);
		GridLayout gl = new GridLayout(4, false);
		composite.setLayout(gl);
		composite.setLayoutData(gd);

		infoLabel = new Label(composite, SWT.NONE);
		gd = new GridData(GridData.FILL_HORIZONTAL);
		gd.heightHint = 20;
		gd.horizontalSpan = 4;
		infoLabel.setLayoutData(gd);

		gd = new GridData();
		gd.widthHint = 100;
		gd.heightHint = 20;
		hsbhLabel = new Label(composite, SWT.RIGHT);
		hsbhLabel.setText("货商编号：");
		hsbhLabel.setLayoutData(gd);
		hsbh = new Text(composite, SWT.BORDER);
		hsbh.setLayoutData(gd);

		hsnameLabel = new Label(composite, SWT.RIGHT);
		hsnameLabel.setText("货商名称：");
		hsnameLabel.setLayoutData(gd);
		hsname = new Text(composite, SWT.BORDER);
		hsname.setLayoutData(gd);

		findBt = new Button(composite, SWT.NONE);
		findBt.setText("查询F7");
		findBt.setLayoutData(gd);
		findBt.addMouseListener(new MouseAdapter() {

			@Override
			public void mouseDown(MouseEvent e) {
				// TODO Auto-generated method stub
				// initial();
				hsid = hsbh.getText();
				hsName = hsname.getText();
				find(hsid, hsName);
			}

		});

		tableViewer = new TableViewer(composite, SWT.BORDER | SWT.H_SCROLL
				| SWT.FULL_SELECTION);
		tableViewer.setUseHashlookup(true);

		gd = new GridData(GridData.FILL_BOTH);
		gd.horizontalSpan = 4;
		table = tableViewer.getTable();
		table.setLayoutData(gd);
		table.setLayout(tableLayout);
		table.setToolTipText("点击单元格对数据进行修改！");
		// 设置行高
		table.addListener(SWT.MeasureItem, new Listener() {
			public void handleEvent(Event event) {
				event.height = 20;
			}
		});

		BussinessInfoEditorSupport editingSupport = new BussinessInfoEditorSupport(
				tableViewer, 1, this);
		createColumn("ID", BusinessInfoSorter.ID_ASC,
				BusinessInfoSorter.ID_DESC, editingSupport);
		editingSupport = new BussinessInfoEditorSupport(tableViewer, 2, this);
		createColumn("货商编号", BusinessInfoSorter.hsid_asc,
				BusinessInfoSorter.hsid_desc, editingSupport);
		manager.addITextKeyChangeListener(editingSupport);
		
		editingSupport = new BussinessInfoEditorSupport(tableViewer, 3, this);
		createColumn("货商名称", BusinessInfoSorter.NAME_ASC,
				BusinessInfoSorter.NAME_DESC, editingSupport);
		manager.addITextKeyChangeListener(editingSupport);
		
		editingSupport = new BussinessInfoEditorSupport(tableViewer, 4, this);
		createColumn("拼音码", BusinessInfoSorter.pym_asc,
				BusinessInfoSorter.pym_desc, editingSupport);
		manager.addITextKeyChangeListener(editingSupport);
		
		editingSupport = new BussinessInfoEditorSupport(tableViewer, 5, this);
		createColumn("货商区域名称", null, null, editingSupport);
		manager.addITextKeyChangeListener(editingSupport);
		
		editingSupport = new BussinessInfoEditorSupport(tableViewer, 6, this);
		createColumn("货商类别名称", null, null, editingSupport);
		manager.addITextKeyChangeListener(editingSupport);
		
		editingSupport = new BussinessInfoEditorSupport(tableViewer, 7, this);
		createColumn("货商联系电话", null, null, editingSupport);
		manager.addITextKeyChangeListener(editingSupport);
		
		editingSupport = new BussinessInfoEditorSupport(tableViewer, 8, this);
		createColumn("货商地址", null, null, editingSupport);
		manager.addITextKeyChangeListener(editingSupport);
		
		editingSupport = new BussinessInfoEditorSupport(tableViewer, 9, this);
		createColumn("联系人", null, null, editingSupport);
		manager.addITextKeyChangeListener(editingSupport);
		
		editingSupport = new BussinessInfoEditorSupport(tableViewer, 10, this);
		createColumn("传真", null, null, editingSupport);
		manager.addITextKeyChangeListener(editingSupport);
		
		editingSupport = new BussinessInfoEditorSupport(tableViewer, 11, this);
		createColumn("邮政编码", null, null, editingSupport);
		manager.addITextKeyChangeListener(editingSupport);
		
		editingSupport = new BussinessInfoEditorSupport(tableViewer, 12, this);
		createColumn("电子邮箱", null, null, editingSupport);
		manager.addITextKeyChangeListener(editingSupport);
		
		editingSupport = new BussinessInfoEditorSupport(tableViewer, 13, this);
		createColumn("银行账号", null, null, editingSupport);
		manager.addITextKeyChangeListener(editingSupport);

		table.setHeaderVisible(true);
		table.setLinesVisible(true);

		// initial the tabelViewer
		tableViewer.setContentProvider(new BusinessInfoContentProvider());
		tableViewer.setLabelProvider(new BusinessInfoLableProvider());
		initial();
		tableViewer.setInput(list);

		table.addListener(SWT.EraseItem, new SetTableColColorListener(table));

		table.select(0);
		table.setFocus();

	}


	@SuppressWarnings("static-access")
	private void createTreeViewer(Composite parent) {
		// TODO Auto-generated method stub
		treeViewer = new TreeViewer(parent, SWT.BORDER | SWT.V_SCROLL
				| SWT.FULL_SELECTION);
		treeViewer.setUseHashlookup(true);

		GridData gd = new GridData();
		gd.verticalAlignment = SWT.TOP;
		final Tree tree = treeViewer.getTree();
		tree.setLayoutData(new GridData(GridData.FILL_VERTICAL));
		final TreeColumn category = new TreeColumn(tree, SWT.LEFT);
		category.setWidth(100);
		category.setText("货商地区");
		treeViewer.setContentProvider(new DistrictTreeContentProvider());
		treeViewer.setLabelProvider(new DistrictTreeLabelProvider());
		treeViewer.setInput(extentionInfo.getInstance().getKeshang());

		tree.setHeaderVisible(true);
		tree.setLinesVisible(true);

		treeViewer.expandToLevel(2);

		treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

			@Override
			public void selectionChanged(SelectionChangedEvent event) {
				// TODO Auto-generated method stub
				IStructuredSelection selection = (IStructuredSelection) event
						.getSelection();
				if (selection.getFirstElement() instanceof KeshangTreeChildren) {
					KeshangTreeChildren ktc = (KeshangTreeChildren) selection
							.getFirstElement();
					String area = ktc.getKeshang().getKeshangarea();
					tableViewer.getTable().clearAll();
					tableViewer.setInput(getHsAreaTpinfo(area, null));
				}
				if (selection.getFirstElement() instanceof KeshangTreeParent) {
					initial();
					tableViewer.getTable().clearAll();
					tableViewer.setInput(list);
				}
				if (selection.getFirstElement() instanceof MerchantTypeTreeChildren) {
					MerchantTypeTreeChildren ktc = (MerchantTypeTreeChildren) selection
							.getFirstElement();
					String type = ktc.getKstype().getKstype();
					tableViewer.getTable().clearAll();
					tableViewer.setInput(getHsAreaTpinfo(null, type));
				}
				if (selection.getFirstElement() instanceof MerchantTypeTreeParent) {
					initial();
					tableViewer.getTable().clearAll();
					tableViewer.setInput(list);
				}

			}

		});

	}

	private void initial() {
		// TODO Auto-generated method stub
		infoLabel.setForeground(Display.getCurrent().getSystemColor(
				SWT.COLOR_BLUE));
		infoLabel.setText("添加，删除，查询相关数据。。。");
		list = getHsinfo(null, null);

	}

	@SuppressWarnings("unchecked")
	private List getHsinfo(String id, String name) {
		// TODO Auto-generated method stub
		List newList = new ArrayList();
		int[] strBuffer = { 0 };
		int[] strBuffer2 = { 0, 1 };
		Object[] idObject = { id };
		Object[] nameObject = { name };
		Object[] Object = { id, name };
		if (id == null && name == null) {
			newList = (List) DbManager.getInstance().search(
					"com.whlilong.jxc.ui.geths");
		} else if (id != null && name == null) {
			newList = (List) DbManager.getInstance().search(
					"com.whlilong.jxc.ui.gethsid", strBuffer, idObject);
		} else if (id == null && name != null) {
			newList = (List) DbManager.getInstance().search(
					"com.whlilong.jxc.ui.gethsname", strBuffer, nameObject);
		} else {
			newList = (List) DbManager.getInstance().search(
					"com.whlilong.jxc.ui.gethsinfo", strBuffer2, Object);
		}
		return list=newList;
	}

	@SuppressWarnings("unchecked")
	private List getHsAreaTpinfo(String area, String type) {
		// TODO Auto-generated method stub
		List<Hsinfo> newlist = new ArrayList<Hsinfo>();
		int[] strBuffer = { 0 };
		Object[] areaObject = { area };
		Object[] typeObject = { type };
		if (area != null && type == null) {
			newlist = (List) DbManager.getInstance().search(
					"com.whlilong.jxc.ui.gethsarea", strBuffer, areaObject);
		}
		if (area == null && type != null) {
			newlist = (List) DbManager.getInstance().search(
					"com.whlilong.jxc.ui.gethstype", strBuffer, typeObject);
		}
		return list=newlist;
	}

	public void print() {
		// TODO Auto-generated method stub
		final PDocument doc = new PDocument("print");

		PTextBox t;

		t = new PTextBox(doc);

		t.setText("武汉立隆客商信息");

		new PVSpace(doc, 0.5);
		new PHLine(doc, 0.02, SWT.COLOR_RED);
		new PVSpace(doc, 0.5);

		// create the table
		SWTPTable swttable = new SWTPTable(doc);
		swttable.setTable(table);
		swttable.setBoxProvider(new PTableBoxProvider());
		
		PrintPreview pr = new PrintPreview(null, "信息打印", IconSource
				.getImage("print"), doc);
		pr.onPrint();
	}

	public void save() {
		// TODO Auto-generated method stub
		if(!isSave){
			MessageDialog.openWarning(null, "提示", "数据不能保存！");
			return;
		}
		manager.notifyListener();
		Iterator data = list.iterator();
		if (!data.hasNext()) {
			MessageDialog.openWarning(null, "提示", "没有需要保存的数据！");
			return;
		}

		Job job = new Job("正在保存数据。。。") {
			@Override
			protected IStatus run(IProgressMonitor monitor) {
				// TODO Auto-generated method stub
				monitor.beginTask("正在保存数据。。。", IProgressMonitor.UNKNOWN);

				for (int i = 0; i < list.size(); i++) {
					Hsinfo hsinfo = (Hsinfo) list.get(i);
					int id = hsinfo.getId();
					int[] idBuffer = { 0 };
					Object[] idObject = { id };
					List result = (List) DbManager.getInstance().search(
							"com.whlilong.jxc.ui.hsinfo.getid", idBuffer,
							idObject);
					CnToSpellFirstChar c = new CnToSpellFirstChar();
					String pym = "";
					if (result.size() > 0) {
						String hsname = hsinfo.getHsname();
						String hsid = hsinfo.getHsid();
						if (hsid != null && !hsid.equals("") && hsname != null
								&& !hsname.equals("")) {
							int count = 0;
							Hsinfo k = (Hsinfo) result.get(0);
							pym = c.makePy(hsname);
							k.setHsid(hsid);
							k.setHsname(hsinfo.getHsname());
							k.setFax(hsinfo.getFax());
							k.setHsaddress(hsinfo.getHsaddress());
							k.setHsareaname(hsinfo.getHsareaname());
							k.setHstel(hsinfo.getHstel());
							k.setHstpname(hsinfo.getHstpname());
							k.setMail(hsinfo.getMail());
							k.setPeople(hsinfo.getPeople());
							k.setPym(pym.substring(0, pym.length()-1));
							k.setYh(hsinfo.getYh());
							k.setYzbm(hsinfo.getYzbm());
							monitor.worked(1);
							DbManager.getInstance().update(k);
						} else {
							return Status.CANCEL_STATUS;
						}

					} else {
						String hsname = hsinfo.getHsname();
						String hsid = hsinfo.getHsid();
						if (hsid != null && !hsid.equals("") && hsname != null
								&& !hsname.equals("")) {
							Hsinfo ks = new Hsinfo();
							pym = c.makePy(hsname);
							ks.setHsid(hsid);
							ks.setHsname(hsname);
							ks.setFax(hsinfo.getFax());
							ks.setHsaddress(hsinfo.getHsaddress());
							ks.setHsareaname(hsinfo.getHsareaname());
							ks.setHstel(hsinfo.getHstel());
							ks.setHstpname(hsinfo.getHstpname());
							ks.setMail(hsinfo.getMail());
							ks.setPeople(hsinfo.getPeople());
							ks.setPym(pym.substring(0, pym.length()-1));
							ks.setYh(hsinfo.getYh());
							ks.setYzbm(hsinfo.getYzbm());
							DbManager.getInstance().insert(ks);
						} else {

							return Status.CANCEL_STATUS;
						}

					}
					list.get(i).setPym(pym.substring(0, pym.length()-1));
				}
				monitor.done();
				return Status.OK_STATUS;
			}

		};
		job.addJobChangeListener(new JobChangeAdapter() {
			public void done(IJobChangeEvent event) {
				final boolean isSuccess = event.getResult().isOK();
				Display.getDefault().asyncExec(new Runnable() {
					public void run() {
						if (isSuccess) {

							MessageDialog.openInformation(null, "提示",
									"数据已经成功保存！");
							tableViewer.setInput(list);
						} else
							MessageDialog.openError(null, "错误", "编号或名称为空，数据保存失败！");
					}
				});
			}
		});
		job.setUser(false);
		job.setPriority(Job.SHORT);
		job.schedule();
	}

	public void refresh() {
		// TODO Auto-generated method stub
		combo.select(0);
		initial();
		treeViewer.getTree().getColumn(0).setText("货商地区");
		treeViewer.setContentProvider(new DistrictTreeContentProvider());
		treeViewer.setLabelProvider(new DistrictTreeLabelProvider());
		treeViewer.setInput(extentionInfo.getInstance().getKeshang());
		treeViewer.expandToLevel(2);
		tableViewer.setInput(list);
	}

	public void create() {
		// TODO Auto-generated method stub
		tableViewer.getTable().setFocus();
		infoLabel.setForeground(Display.getCurrent().getSystemColor(
				SWT.COLOR_BLUE));
		infoLabel.setText("提示：请点击参数单元格来添加修改数据，输入完成后点击保存！");
		list = getHsinfo(null, null);
		List tableList = (List) tableViewer.getInput();
		Hsinfo hs = new Hsinfo();
		Hsinfo h = new Hsinfo();
		if (list.size() == 0 && tableList.size()==0) {
			hs.setId(1);
			hs.setHsid("");
			hs.setHsname("");
			hs.setHsareaname("不定");
			hs.setHstpname("不定");
			hs.setHstel("");
			hs.setHsaddress("");
			hs.setPeople("");
			hs.setFax("");
			hs.setYzbm("");
			hs.setMail("");
			hs.setYh("");
			hs.setPym("");

			tableViewer.add(hs);
			list.add(hs);
			tableList.add(hs);
			int t = tableViewer.getTable().getItemCount();
			tableViewer.getTable().setSelection(t - 1);
		} else {
			h = (Hsinfo) tableList.get(tableList.size() - 1);
			if (h.getHsid() == null || h.getHsid().equals("")
					|| h.getHsname() == null || h.getHsname().equals("")) {
				infoLabel.setForeground(Display.getCurrent().getSystemColor(
						SWT.COLOR_RED));
				infoLabel.setText("警告：请输入完整数据再进行添加！");
			} else {
				int id = h.getId();
				hs.setId(id + 1);
				hs.setHsid("");
				hs.setHsname("");
				hs.setHsareaname("不定");
				hs.setHstpname("不定");
				hs.setHstel("");
				hs.setHsaddress("");
				hs.setPeople("");
				hs.setFax("");
				hs.setYzbm("");
				hs.setMail("");
				hs.setYh("");
				hs.setPym("");

				tableViewer.add(hs);
				list.add(hs);
				tableList.add(hs);
				int t = tableViewer.getTable().getItemCount();
				for (int i = 0; i < t; i++) {
					if (((Hsinfo) table.getItem(i).getData()).getId() == id + 1) {
						table.select(i);
					}
				}
			}
		}
	}

	public void delete() {
		// TODO Auto-generated method stub
		IStructuredSelection selection = (IStructuredSelection) tableViewer
				.getSelection();
		Hsinfo ks = (Hsinfo) selection.getFirstElement();
		if (!selection.isEmpty()) {
			if (MessageDialog.openConfirm(null, "提示", "你确定删除数据吗？")) {
				delete(ks);
			}
		} else {
			MessageDialog.openConfirm(null, "提示", "请从表格中选择一行数据进行删除！");
		}
	}

	private void delete(Hsinfo hs) {
		// TODO Auto-generated method stub
		String bussinessInfoid = hs.getHsid();
		if (!bussinessInfoid.isEmpty()) {
			int[] idBuffer = { 0 };
			Object[] idObject = { bussinessInfoid };
			List result = (List) DbManager.getInstance().search(
					"com.whlilong.jxc.ui.gethsid", idBuffer, idObject);
			Hsinfo bussinessInfo = (Hsinfo) result.get(0);
			DbManager.getInstance().delete(bussinessInfo);
		}
		refresh();
	}

	public void search() {
		// TODO Auto-generated method stub
		initial();
		hsid = hsbh.getText();
		hsName = hsname.getText();
		find(hsid, hsName);

	}

	private void find(String id, String name) {
		// TODO Auto-generated method stub
		if ((id == null || id.equals("")) && (name == null || name.equals(""))) {
			tableViewer.setInput(getHsinfo(null, null));
		} else if ((id != null || !id.equals(""))
				&& (name == null || name.equals(""))) {
			tableViewer.setInput(getHsinfo(id, null));
		} else if ((id == null || id.equals(""))
				&& (name != null || !name.equals(""))) {
			tableViewer.setInput(getHsinfo(null, name));
		} else {
			tableViewer.setInput(getHsinfo(id, name));
		}
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

	@Override
	public void searchByCondition() {
		Shell subshell = new Shell(shell, SWT.DIALOG_TRIM);
		BusinessInfoSearchByConditon sb = new BusinessInfoSearchByConditon(subshell);
		sb.open();
		if (!sb.isCacel()) {
			list = sb.getList();
			tableViewer.setInput(list);
		}
	}

	@Override
	public void addInfo() {
		// TODO Auto-generated method stub

	}

	@Override
	public List getList() {
		return this.list;
	}


	@Override
	public void noticeFault(String message) {
		infoLabel.setForeground(Display.getCurrent().getSystemColor(
				SWT.COLOR_RED));
		infoLabel.setText(message);
		this.isSave  = false;
	}

	@Override
	public void noticeSuccess() {
		infoLabel.setText("");
		this.isSave = true;
	}

	@Override
	public void preprint() {
		// TODO Auto-generated method stub
		final PDocument doc = new PDocument("print");

		PTextBox t;

		t = new PTextBox(doc);

		t.setText("武汉立隆客商信息");

		new PVSpace(doc, 0.5);
		new PHLine(doc, 0.02, SWT.COLOR_RED);
		new PVSpace(doc, 0.5);

		// create the table
		SWTPTable swttable = new SWTPTable(doc);
		swttable.setTable(table);
		swttable.setBoxProvider(new PTableBoxProvider());
		
		PrintPreview pr = new PrintPreview(null, "信息打印", IconSource
				.getImage("print"), doc);
		pr.open();
	}

}
